<div id="tab8" class="tab">
    <div class="tab-labels">
        <div class="xian"></div>
        本车人伤
    </div>
    <div style="border:1px solid #FF5722; padding-top: 10px;">
        <table class="layui-table" id="tabProduct2">
            <tr style="background:#4e73df;color: #fff;" class="ys">
                <td style="width: 66px;">选择</td>
                <!--<td>服务种类</td>-->
                <td>姓名</td>
                <td>性别</td>
                <td>年龄</td>
                <td>户籍性质</td>
                <td>医疗机构</td>
                <td>病案号</td>
                <td>金额</td>
                <td>核价金额</td>
                <td>备注</td>
            </tr>
            {empty name="benren"}
            <tr>
                <td><input type="checkbox" style="width: 15px;height: 15px;display: block;" name="id"
                           readonly value=""></td>
                <!--<td><input type="text" name="type" readonly></td>-->
                <td><input type="text" name="name" readonly></td>
                <td><input type="text" name="sex" readonly></td>
                <td><input type="text" name="age" readonly></td>
                <td><input type="text" name="quality" readonly></td>
                <td><input type="text" name="nuit" readonly></td>
                <td><input type="text" name="number" readonly></td>
                <td><input type="text" name="money" readonly></td>
                <td><input type="text" name="hejia" readonly></td>
                <td><input type="text" name="beizhu" readonly></td>
            </tr>
            {/empty}
            {volist name='benren' id="benrens"}
            <tr>
                <td><input type="checkbox" style="width: 15px;height: 15px;display: block;" name="id"
                           readonly value="{$benrens.id}"></td>
                <!-- <td><input type="text" name="type" value="{$benrens.type}" readonly></td> -->
                <td><input type="text" name="name" readonly value="{$benrens.name}"
                           onclick="openDialogs1({$benrens.id})"
                           style='text-decoration: underline;color:blue;cursor: pointer;'></td>
                <td><input type="text" name="sex" readonly value="{$benrens.sex}"></td>
                <td><input type="text" name="age" readonly value="{$benrens.age}"></td>
                <td><input type="text" name="quality" readonly value="{$benrens.quality}"></td>
                <td><input type="text" name="nuit" readonly value="{$benrens.nuit}"></td>
                <td><input type="text" name="number" readonly value="{$benrens.number}"></td>
                <td><input type="text" name="money" readonly value="{$benrens.money}"></td>
                <td><input type="text" class="hejia1" name="hejia" value="{$hd_sum}" oninput="v1()">
                </td>
                <td><input type="text" name="beizhu" readonly value="{$benrens.beizhu}"></td>
            </tr>
            {/volist}
        </table>
        <table class="layui-table" id="he2">
            <tr>
                <td>小计</td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly></td>
                <td><input type="text" readonly id="benren_money" name="benren_money"
                           value="{$row.benren_money}"></td>
                <td><input type="text" readonly id="benren_hejia" name="benren_hejia"
                           value="{$row.benren_hejia}"></td>
                <td><input type="text" readonly></td>
            </tr>
        </table>
        <!--<p>汇总</p>-->
        <div class="conts" style="display:none;">
            <div class="input">
                <span>费用合计</span>
                <input type="text" readonly value="{$row.br_heji}" name="br_heji" id="br_heji">
            </div>
        </div>
        <script>
            function v1() {
                var hejias = $('.hejia1');
                var benren_hejia = $('#benren_hejia');
                var br_heji = $('#br_heji');
                var hejia = 0;
                for (var i = 0; i < hejias.length; i++) {
                    hejia += Number(hejias[i].value);
                }
                benren_hejia.val(hejia);
                br_heji.val(hejia);
            }
        </script>
        <div class="conts" style="display: none">
            <div class="input">
                <span>诉讼费</span>
                <input type="text" id="benren_susong" value="{$row.benren_susong}" name="benren_susong"
                       readonly>
            </div>
            <div class="input">
                <span>鉴定费</span>
                <input type="text" id="benren_jianding" value="{$row.benren_jianding}"
                       name="benren_jianding" readonly>
            </div>
            <div class="input">
                <span>公估费</span>
                <input type="text" id="benren_gonggu" value="{$row.benren_gonggu}" name="benren_gonggu"
                       readonly>
            </div>
            <div class="input">
                <span>住宿费</span>
                <input type="text" id="benren_zhusu" value="{$row.benren_zhusu}" name="benren_zhusu"
                       readonly>
            </div>
            <div class="input">
                <span>路桥费</span>
                <input type="text" id="benren_luqiao" value="{$row.benren_luqiao}" name="benren_luqiao"
                       readonly>
            </div>
            <div class="input">
                <span>燃油费</span>
                <input type="text" id="benren_ranyou" value="{$row.benren_ranyou}" name="benren_ranyou"
                       readonly>
            </div>
            <div class="input">
                <span>其他</span>
                <input type="text" id="benren_qita" value="{$row.benren_qita}" name="benren_qita"
                       readonly>
            </div>
            <div class="input">
                <span>合计</span>
                <input type="text" id="benren_heji" value="{$row.benren_heji}" name="benren_heji"
                       readonly>
            </div>
        </div>
        <div class="conts" style="display: none">
            <div class="input">
                <button style="margin: 1%;margin-top:20px;" onclick="bbaocun()" type="button">保存
                </button>
            </div>
        </div>

        <hr>
        <?php if( request()->controller()== "Bushen.hejia"){?>
        <div class="conts">
            <span style="width:98%;margin: 1%;">审核意见</span>
            <textarea name="" id="renshang_1_text" cols="30" rows="10"
                      style="width:98%;height: 100px;margin: 1%;"></textarea>
        </div>
        <div style="padding: 10px;display: flex;justify-content: center;">

            <button type="button" class="layui-btn layui-btn-danger" id="renshang_1">本车人伤通过审核
            </button>
            <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_11">无损失</button>-->
            <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_12">未参统</button>-->
            <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_13">无需补偿</button>-->

            <button type="button" class="layui-btn layui-btn-warm" id="renshang_bk1">退回</button>

        </div>
        <?php }?>
        <script>
            $('#renshang_1').click(function () {
                var renshang_1_text = $('#renshang_1_text').val();
                if (renshang_1_text == '') {
                    layer.msg("请输入审核原因");
                    return false
                }
                layer.confirm('确定' + $(this).text() + '？', {
                    icon: 3,
                    title: $(this).text()
                }, function (index) {
                    $.ajax({
                        url: "{:url('bushen/hejia/shenhe_post')}",
                        data: {
                            id: "{$orderid}",
                            bid: "{$bid}",
                            renshang_1: 3,
                            tuihui: renshang_1_text,
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function (res) {
                            if (res.code == 1) {
                                layer.msg(res.msg, {time: 2000}, function () {
                                    layer.closeAll()
                                    parent.layer.closeAll();
                                    parent.$("#table").bootstrapTable('refresh', {});
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                });
            })


            $('#renshang_bk1').click(function () {
                var renshang_1_text = $('#renshang_1_text').val();
                if (renshang_1_text == '') {
                    layer.msg("请输入审核原因");
                    return false
                }
                layer.confirm('确定' + $(this).text() + '？', {
                    icon: 3
                }, function (index) {
                    $.ajax({
                        url: "{:url('bushen/hejia/shenhe_post')}",
                        data: {
                            id: "{$orderid}",
                            bid: "{$bid}",
                            renshang_1: 2,
                            tuihui: renshang_1_text,
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function (res) {
                            if (res.code == 1) {
                                layer.msg(res.msg, {time: 2000}, function () {
                                    layer.closeAll()
                                    parent.layer.closeAll();
                                    parent.$("#table").bootstrapTable('refresh', {});
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                });
            })
        </script>

        <script>
            function bbaocun() {
                var money = $('#benren_money').val();
                var hejia = $('#benren_hejia').val();
                var br_heji = $('#br_heji').val();
                var susong = $('#benren_susong').val();
                var jianding = $('#benren_jianding').val();
                var gonggu = $('#benren_gonggu').val();
                var zhusu = $('#benren_zhusu').val();
                var luqiao = $('#benren_luqiao').val();
                var ranyou = $('#benren_ranyou').val();
                var qita = $('#benren_qita').val();
                var heji = $('#benren_heji').val();
                var bid = $('#bid').val();
                $.ajax({
                    url: "{:url('buchang/bbaocun')}",
                    data: {
                        benren_money: money,
                        benren_hejia: hejia,
                        br_heji: br_heji,
                        benren_susong: susong,
                        benren_jianding: jianding,
                        benren_gonggu: gonggu,
                        benren_zhusu: zhusu,
                        benren_luqiao: luqiao,
                        benren_ranyou: ranyou,
                        benren_qita: qita,
                        benren_heji: heji,
                        bid: bid
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        layer.msg(res.msg);
                    }
                })
            }
        </script>
        <div id="light1" class="white_content">
            <form action="" id="benren_form">
                <input type="hidden" value="{$row.id}" name="id">
                <div class="conts">
                    <div class="input">
                        <span>诊断病情</span>
                        <input type="text" name="bingqing" value="" readonly id="bingqing">
                    </div>
                    <div class="input">
                        <span>是否住院</span>
                        <select name="zhuyuan" id="zhuyuan" disabled>
                            <option value="是">是</option>
                            <option value="否">否</option>
                        </select>
                    </div>
                    <div class="input">
                        <span>住院天数</span>
                        <input type="text" name="zhuyuan_date" readonly value="" id="zhuyuan_date">
                    </div>
                    <div class="input">
                        <span>是否残疾</span>
                        <select name="canji" id="canji" disabled>
                            <option value="是">是</option>
                            <option value="否">否</option>
                        </select>
                    </div>
                </div>
                <div class="content">
                    <input type="hidden" name="bid" class="benid">
                    {if $benren[0]['status'] eq 1}
                    <input type="button" onclick="benren(this)" value="保存数据"
                           style="padding: 5px 10px;height:30px;border: none;background:#1b4fe7;color: #fff;">
                    {/if}
                    <table class="layui-table" id="tabProducts">
                        <tr style="background: #4e73df;color:#fff;">
                            <td style="width: 66px;">选择</td>
                            <td>序号</td>
                            <!--<td>服务种类</td>-->
                            <td>费用类型</td>
                            <td>金额</td>
                            <td>数量</td>
                            <td>总价</td>
                            <td>核价金额</td>
                            <td>备注</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" style="width: 15px;height: 15px;display: block;"
                                       name="id" readonly value=""/></td>
                            <td><input type="text" class="xuhao6" name="xuhao" value="1" readonly/></td>
                            <!--<td><input type="text" name="type" readonly/></td>-->
                            <td><input type="text" name="leixing" readonly/></td>
                            <td><input type="text" name="price" readonly/></td>
                            <td><input type="text" name="num" readonly/></td>
                            <td><input type="text" name="money" readonly/></td>
                            <td><input type="text" name="hejia" readonly/></td>
                            <td><input type="text" name="beizhu" readonly/></td>
                        </tr>
                    </table>
                    <table class="layui-table" id="hes">
                        <tr>
                            <td>小计</td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly></td>
                            <!-- <td><input type="text" readonly></td> -->
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly value="" name="money" id="bren_money"
                                       class="bren_money"></td>
                            <td><input type="text" readonly value="" name="hejia" id="bren_hejia"
                                       class="bren_hejia"></td>
                            <td><input type="text" readonly></td>
                        </tr>
                    </table>
                    <script>
                        function v2() {
                            var hejias = $('.hejia6');
                            var bren_hejia = $('#bren_hejia');
                            var hejia = 0;
                            for (var i = 0; i < hejias.length; i++) {
                                hejia += Number(hejias[i].value);
                            }
                            bren_hejia.val(hejia);
                        }

                        function benren(sub) {
                            layer.confirm('请确认是否已填完数据', {
                                icon: 3,
                            }, function (index) {
                                var ids = $('.bid6');
                                var hejias = $('.hejia6');
                                var bids = $('.benid');
                                var id = new Array();
                                var hejia = new Array();
                                var sid = new Array();
                                for (var i = 0; i < ids.length; i++) {
                                    id[i] = ids[i].value;
                                }

                                for (var i = 0; i < hejias.length; i++) {
                                    hejia[i] = hejias[i].value;
                                }
                                var sum = $("#bren_hejia").val();
                                $.ajax({
                                    url: "{:url('bushen/hejia/hd_benrens')}",
                                    data: {
                                        id: id,
                                        bid: "{$bid}",
                                        hejia: hejia,
                                        sum: sum,
                                    },
                                    type: 'post',
                                    dataType: 'json',
                                    success: function (res) {
                                        layer.msg(res.msg);
                                        sub.onclick = '';
                                    }
                                })
                            });
                        }
                    </script>
                    <div class="conts">
                        <div class="input">
                            <button style="margin: 1%;margin-top:20px;display: none;" type="button"
                                    onclick="closeDialog1s()">保存
                            </button>
<!--                            <button style="margin: 1%;margin-top:20px;" type="button"-->
<!--                                    onclick="closeDialog1()">关闭-->
<!--                            </button>-->
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div id="fade1" class="black_overlay"></div>
        <script type="text/javascript">
            function openDialogs1(id) {
                // 1. 先打开弹窗（显示加载中状态）
                var $light2Content = $('#light1').contents(); // 先保存引用
                var layerIndex = layer.open({
                    type: 1,
                    title: '加载中...',
                    content: `
                    <div style="
                      position: absolute;
                      top: 50%;
                      left: 50%;
                      transform: translate(-50%, -50%);
                      text-align: center;
                    ">
                      <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
                      <p style="margin-top: 10px">加载中...</p>
                    </div>
                  `,
                    end: function() {
                        // 弹窗关闭时，把内容放回 #light2
                        $('#light1').append($light2Content);
                    },
                    area: ['80%', '80%'],
                    shadeClose: false // 禁止点击遮罩关闭
                });
                $.ajax({
                    url: "{:url('bushen/hejia/benrens')}",
                    data: {id: id},
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == true) {
                            var html = '';
                            if (res.data.renshang.length > 0) {
                                for (var i = 0; i < res.data.renshang.length; i++) {
                                    html += "<tr>" +
                                        "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' class='bid6' readonly name='id' value=" + res.data.renshang[i].id + "></td>" +
                                        "<td><input type='text' class='xuhao6' name='xuhao' readonly value=" + res.data.renshang[i].xuhao + "></td>" +
                                        "<td><input type='text' class='leixing6' name='leixing' readonly value=" + res.data.renshang[i].leixing + "></td>" +
                                        "<td><input type='text' class='price6' name='price' readonly value=" + res.data.renshang[i].price + "></td>" +
                                        "<td><input type='text' class='num6' name='num' readonly value=" + res.data.renshang[i].num + "></td>" +
                                        "<td><input type='text' class='money6' name='money' readonly value=" + res.data.renshang[i].money + "></td>" +
                                        "<td><input type='text' class='hejia6' name='hejia' oninput='v2()' value=" + res.data.renshang[i].hejia + "></td>" +
                                        "<td><input type='text' class='beizhu6' name='beizhu' readonly value=" + res.data.renshang[i].beizhu + "></td>" +
                                        "</tr>";
                                }
                            } else {
                                html += "<tr>" +
                                    "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' name='id' readonly value=''></td>" +
                                    "<td><input type='text' name='xuhao' value='1' readonly class='xuhao6'></td>" +
                                    "<td><input type='text' name='leixing' readonly value=''></td>" +
                                    "<td><input type='text' name='price' readonly value=''></td>" +
                                    "<td><input type='text' name='num' readonly value=''></td>" +
                                    "<td><input type='text' name='money' readonly value=''></td>" +
                                    "<td><input type='text' name='hejia' readonly value=''></td>" +
                                    "<td><input type='text' name='beizhu' readonly value=''></td>" +
                                    "</tr>";
                            }
                            $("#tabProducts tr").slice(1).remove();
                            $('#tabProducts').append(html);
                            $('#bingqing').val(res.data.benren.bingqing);
                            $('#zhuyuan').val(res.data.benren.zhuyuan);
                            $('#zhuyuan_date').val(res.data.benren.zhuyuan_date);
                            $('#canji').val(res.data.benren.canji);
                            // $('#bren_money').val(res.data.benren.money);
                            // $('#bren_hejia').val(res.data.benren.hejia);
                            $('.benid').val(res.data.benren.id);

                            var money6 = $('.money6');
                            console.log(money6)
                            var hejia6 = $('.hejia6');
                            var sum = 0;
                            for (var i = 0; i < money6.length; i++) {
                                console.log(money6[i].value)
                                sum += Number(money6[i].value);
                            }
                            $('#bren_money').val(sum.toFixed(2));
                            sum = 0;
                            for (var i = 0; i < hejia6.length; i++) {
                                sum += Number(hejia6[i].value);
                            }
                            $('#bren_hejia').val(sum.toFixed(2));
                            layer.title('详情', layerIndex); // 修改标题
                            // $('#layui-layer' + layerIndex).find('.layui-layer-content').html($('#light1').html()); // 更新内容
                            $('#layui-layer' + layerIndex)
                                .find('.layui-layer-content')
                                .empty() // 先清空目标容器
                                .append($('#light1').contents()); // 移动 #light2 的子节点（不复制）
                        }else{
                            layer.msg(res.msg || '数据加载失败', {icon: 2});
                        }
                    }
                })
            }

            function closeDialog1s() {
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "{:url('bushen/hejia/renshangs')}",//url
                    data: $('#benren_form').serialize(),
                    success: function (res) {
                        console.log(res);//打印服务端返回的数据(调试用)
                        layer.msg(res.msg);
                        if (res.code == true) {
                            var html = '';
                            if (res.ress.length > 0) {
                                for (var i = 0; i < res.ress.length; i++) {
                                    html += "<tr>" +
                                        "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' name='id' disabled value=" + res.ress[i].id + "></td>" +
                                        "<td><input type='text' readonly name='type' value=" + res.ress[i].type + "></td>" +
                                        "<td><input type='text' readonly name='name' onclick='openDialogs1(this)' style='text-decoration: underline;color:blue;cursor: pointer;' value=" + res.ress[i].name + "></td>" +
                                        "<td><input type='text' readonly name='sex' value=" + res.ress[i].sex + "></td>" +
                                        "<td><input type='text' readonly name='age' value=" + res.ress[i].age + "></td>" +
                                        "<td><input type='text' readonly name='quality' value=" + res.ress[i].quality + "></td>" +
                                        "<td><input type='text' readonly name='nuit' value=" + res.ress[i].nuit + "></td>" +
                                        "<td><input type='text' readonly name='num' value=" + res.ress[i].number + " ></td>" +
                                        "<td><input type='text' name='money' readonly value=" + res.ress[i].money + "></td>" +
                                        "<td><input type='text' name='hejia' class='hejia1' oninput='v1()' value=" + res.ress[i].hejia + "></td>" +
                                        "<td><input type='text' readonly name='beizhu' value=" + res.ress[i].beizhu + "></td>" +
                                        "</tr>";
                                }
                                $("#tabProduct2 tr").slice(1).remove();
                                $('#tabProduct2').append(html);
                                v1();
                            }
                        }
                    },
                });
                $('#light1').css("display",'none');
                $('#fade1').css("display",'none')
            }

            function closeDialog1() {
                // var message = confirm('请确认是否已填完数据');
                // if (message) {
                $('#light1').css("display",'none');
                $('#fade1').css("display",'none')
                // }
            }
        </script>
    </div>
    <script type="text/javascript">
        function test(obj) {

            var div1 = $("#div1");
            if (div1.style.display == "block") {
                div1.style.display = "none";
            } else {
                div1.style.display = "block";
            }
        }
    </script>

</div>